#include <cmath>
#include <cstdlib>
#include <ctime>

#include "Utils.hpp"

Vector2d::Vector2d() : X(0), Y(0)
{
}

Vector2d::Vector2d(int x, int y) : X(x), Y(y)
{
}

int Vector2d::getDistanceFrom(Vector2d other)
{
	return (int)sqrt(pow((double)(other.X - X), 2) + pow((double)(other.Y - Y), 2));
}

bool Vector2d::operator == (Vector2d other)
{
	return (Y == other.Y && X == other.X);
}

bool Vector2d::operator != (Vector2d other)
{
	return !(*this == other);
}

Vector2d& Vector2d::operator += (Vector2d other)
{
	X += other.X;
	Y += other.Y;
	return *this;
}

Vector2d Vector2d::operator + (Vector2d other)
{
	return Vector2d(X+other.X, Y+other.Y);
}

int Utils::rollDice(TCOD_dice_t dice)
{
    float ret = 0;
    for (int i = 0; i < dice.nb_dices; ++i)
        ret += TCODRandom::getInstance()->getInt(1, dice.nb_faces);
    ret *= dice.multiplier;
    ret += dice.addsub;
    return (int)ret;
}

unsigned int Utils::random0ToN(unsigned int size)
{
	srand((unsigned)time(NULL));
	int res = rand() % size;
	return res;
}
